<template>
  <div class="user-item">
    <div class="item-left">
      <el-avatar :shape="'square'" :src="user.friendAvatar ?? circleUrl" />
    </div>
    <div class="item-center">
      {{ user.nickName }}
    </div>
    <div class="item-right">
      <el-button v-if="user.isFriend" type="primary" @click="toChat(user.friendUserId)">
        发消息
      </el-button>
      <el-button v-else type="primary" @click="addFriend(user)">加好友</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { AddChatFriend, ChatFriend } from "@/api/chat/friend/model";
import FileApi from "@/api/file";

const circleUrl = FileApi.GetDefaultUserAvatar();
const props = defineProps({
  user: Object as PropType<ChatFriend>,
});

const addFriend = async (friend: AddChatFriend) => {
  emits("addFriend", friend);
};

const toChat = (userId: string) => {
  emits("toChat", userId);
};

const emits = defineEmits(["toChat", "addFriend"]);
</script>

<style scoped lang="scss">
.user-item {
  display: flex;
  flex-direction: row;
  width: 100%;
  padding: 8px 12px;
  box-sizing: border-box;

  .item-left {
    display: flex;
    align-items: center;
    // .user-avatar {
    //   width: 50px;
    //   border-radius: 4px;
    // }
  }

  .item-center {
    flex: 1;
    display: flex;
    align-items: center;
    text-align: left;
    padding: 0 8px;
  }

  .item-right {
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
</style>
